{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f66f7c88-c0cc-4251-a301-a6e373921d34",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/flatten-binary-tree-to-linked-list\n",
    "\n",
    "\n",
    "Runtime: 40 ms, faster than 68.21% of Python3 online submissions for Flatten Binary Tree to Linked List.\n",
    "Memory Usage: 15.2 MB, less than 75.33% of Python3 online submissions for Flatten Binary Tree to Linked List.\n",
    "\n",
    "\n",
    "```python\n",
    "class Solution:\n",
    "    def flatten(self, root: Optional[TreeNode]) -> None:\n",
    "        \"\"\"\n",
    "        Do not return anything, modify root in-place instead.\n",
    "        \"\"\"\n",
    "        #9:09\n",
    "        nodeList = []\n",
    "        def travel(node):\n",
    "            current = node\n",
    "            if current == None:\n",
    "                return\n",
    "            nodeList.append(node)\n",
    "            travel(node.left)\n",
    "            travel(node.right)\n",
    "        \n",
    "        travel(root)\n",
    "        \n",
    "        if len(nodeList) == 0: return None;\n",
    "        \n",
    "        head = nodeList[0]\n",
    "        for index, node in enumerate(nodeList):\n",
    "            if index+1 < len(nodeList):\n",
    "                node.left = None\n",
    "                node.right = nodeList[index+1]\n",
    "            if index == len(nodeList) - 1:\n",
    "                node.left = None\n",
    "                node.right = None\n",
    "        return head\n",
    "        #9:12\n",
    "        #debug until 9:15\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "773d3c0e-a09d-4766-951e-816915c00be0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
